package cn.tedu.ivos.dict.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.dict.Service.DictService;
import cn.tedu.ivos.dict.pojo.dto.DictAddParam;
import cn.tedu.ivos.dict.pojo.dto.DictQuery;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1/dict/")
@Tag(name = "字典模块")
@Slf4j
public class DictController {
    @Autowired
    DictService dictService;

    @GetMapping("select")
    @Operation(summary = "查询字典项")
    @ApiOperationSupport(order = 10)
    public JsonResult selectDict(DictQuery query) {
        log.debug("查询字典项业务 query{}", query);
        return JsonResult.ok(dictService.selectDict(query));
    }

    @PostMapping("save")
    @Operation(summary = "保存字典项")
    @ApiOperationSupport(order = 20)
    public JsonResult saveDict(@Validated DictAddParam dictAddParam) {
        log.debug("保存字典项业务 query{}",dictAddParam);
        dictService.saveDict(dictAddParam);
        return JsonResult.ok();
    }

    @GetMapping("delete/{id}")
    @Operation(summary = "删除字典项")
    @ApiOperationSupport(order = 30)
    public JsonResult deleteDict(@PathVariable Long id) {
        log.debug("删除字典项业务 id{}",id);
        dictService.deleteDict(id);
        return JsonResult.ok();
    }


}
